'use strict'

import Vue from 'vue'
import request from '@/api/request'
import Toast from 'muse-ui-toast'

Plugin.install = function(Vue, options) {
  if (!options) {
    options = {
      window: false,
      $axios: false,
      catch: true
    }
  }
  Vue.axios = request
  if (options.window) {
    window.axios = request
  }
  if (options.catch) {
    Vue.prototype.$apiCatch = function(err) {
      Toast.error(err.message)
    }
  }
  Object.defineProperties(Vue.prototype, {
    axios: {
      get() {
        return request
      }
    }
  })
  if (options.$axios) {
    Object.defineProperties(Vue.prototype, {
      $axios: {
        get() {
          return request
        }
      }
    })
  }
}

Vue.use(Plugin)

export default Plugin
